#!/bin/bash
clear

RED="\033[31m"    # Error message
GREEN="\033[32m"  # Success message
YELLOW="\033[33m" # Warning message
BLUE="\033[36m"   # Info message
RESET='\033[0m'   # Reset colors

if [[ "$EUID" -ne 0 ]]; then
  echo -e "${RED} Anda tiada kebenaran untuk menjalankan skrip ini! ${RESET}"
  exit 1
fi

wget -q "https://github.com/ambrop72/badvpn/archive/refs/tags/1.999.130.tar.gz"
tar xzf 1.999.130.tar.gz
cd badvpn-1.999.130
cmake -DBUILD_NOTHING_BY_DEFAULT=1 -DBUILD_UDPGW=1
make install

echo "[Unit]
Description=Badvpn-udpgw Service
Documentation=https://github.com/ambrop72/
Wants=network.target
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/badvpn-udpgw --listen-addr 127.0.0.1:7300
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target" >/etc/systemd/system/badvpn-udpgw.service

systemctl daemon-reload
systemctl enable badvpn-udpgw
systemctl start badvpn-udpgw

echo
echo -e "${GREEN} Pemasangan badvpn-udpgw pakej telah selesai. ${RESET}"
echo
